﻿using Dos.ORM;
using JT808.Repository.Models;
using Microsoft.Extensions.Options;
using System;

namespace JT808.Repository.Core
{
    public class JT808DataRepository
    {
        private DbSession Context;
        IOptionsMonitor<RepositoryOptions> optionsMonitor;
        public JT808DataRepository(IOptionsMonitor<RepositoryOptions> optionsMonitor)
        {
            this.optionsMonitor = optionsMonitor;
            Context = new DbSession(DatabaseType.SqlServer9, optionsMonitor.CurrentValue.ConnectionString);
        }
        public JT808DataRepository(string connectionString)
        {
            Context = new DbSession(DatabaseType.SqlServer9, connectionString);
        }
        public int AddMsgLog(JT808MsgLog log)
        {
            return Context.Insert(log);
        }

        public int AddJT808Terminal(JT808Terminal entity)
        {
            return Context.Insert(entity);
        }
        public int UpdateJT808Terminal(JT808Terminal entity)
        {
            return Context.Save(entity);
        }

        public JT808Terminal getTerminalByCode(string code)
        {
            return Context.From<JT808Terminal>().Where(JT808Terminal._.Code == code).First();
        }
    }
}
